package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.AbstractAccount;

public class CheckingAccount extends AbstractAccount {
    protected double overdraft;

    public double getOverdraft() {
        return overdraft;
    }

    public CheckingAccount(double balance, double overdraft) {
        super(balance);
        assert(overdraft >= 0);
        this.overdraft = overdraft;
    }

    public void deposit(double amount) {
        this.balance += amount;
    }

    public void withdraw(double amount) throws RuntimeException {
        if (this.balance + this.overdraft >= amount) {
            this.balance -= amount;
        } else {
            throw new RuntimeException("Недостаточный баланс");
        }
        assert(maximumAmountToWithdraw() >= 0);

        //unnecessary
        assert(overdraft >= 0);
    }

    public double maximumAmountToWithdraw() {
        return this.balance + this.overdraft;
    }

}
